﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using E_Shop.Common;
using ESHOP.DAO;
using ESHOP.Domain;
using ESHOP.UTIL;

namespace E_Shop
{
    public partial class ShoppingCard : Authentication
    {
        
        private SanPhamDAO _sanphamDao = new SanPhamDAO();
        private SANPHAM _sanpham = new SANPHAM();
        private GioHangDAO _giohangDao = new GioHangDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDataforRepeater();
            }
            

        }
        private void BindDataforRepeater()
        {
            if (Session[Constants.SESSION_LOGIN] == null)
            {
                Response.Redirect(WebUrl.LOGIN);
            }
            else
            {
                var giohangs = _giohangDao.GetListBuyCompanyId(Acount.MACT);
                gvList.DataSource = giohangs;
                gvList.DataBind();
                UpGrid.Update();
            }
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var buyId = e.CommandArgument.ToString();            
            var objectGioHang = _giohangDao.Get(int.Parse(buyId));
            var idname = e.CommandName;

            Session[Constants.SESSION_GIOHANG] = objectGioHang;


            switch (idname)
            {
                case "delete":
                    {
                        _giohangDao.Delete(objectGioHang.ID);
                        BindDataforRepeater();
                        Response.Redirect("ShoppingCard.aspx", true);
                        break;
                    }
                case "checkout":
                    {
                        Response.Redirect("ShoppingCheckOut.aspx");
                        break;
                    }
            }
        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }
    }
}